package com.guoxin.designpattern.chapter1;

import java.util.stream.IntStream;

/**
 * 单例模式，双重验锁，线程安全
 * 
 * @author guoxin
 * @date 2019年8月26日
 */
public class SingletonObject7 {

	private SingletonObject7() {
		// empty
	}

	private enum Singleton {
		//
		INSTANCE;
		private SingletonObject7 instance;

		private Singleton() {
			instance = new SingletonObject7();
		}
	}

	public static SingletonObject7 getInstance() {
		return Singleton.INSTANCE.instance;
	}

	public static void main(String[] args) {
		IntStream.rangeClosed(0,100).forEach(i-> new Thread(String.valueOf(i)){
			@Override
			public void run() {
				System.out.println(SingletonObject7.getInstance());
			}
		}.start());
	}
}
